#include<stdio.h>
#include<stdlib.h>
#define TURE 1
#define FALSE 0
typedef struct
{
	int *element;
	int MAXSIZE;
	int front;
	int rear;
}SeqQueue;

void InitQueue(SeqQueue *Q,int msize)
{
	Q->MAXSIZE=msize;
	Q->element=(int*)malloc(msize*(sizeof(int)));
	Q->front=Q->rear=0;
} 
int EnterQueue(SeqQueue *Q,int x)
{
	if((Q->rear+1)%Q->MAXSIZE==Q->front)
	{
		return(FALSE);
		
	}
	Q->element[Q->rear]=x;
	Q->rear=(Q->rear+1)%Q->MAXSIZE;
	return(TURE);
}
int DeleteQueue(SeqQueue *Q,int *x)
{
	if(Q->front==Q->rear)
		return(FALSE);
	*x=Q->element[Q->front];
	Q->front=(Q->front+1)%Q->MAXSIZE;
	return(TURE); 
} 
int GetHead(SeqQueue *Q,int *x)
{
	if(Q->front==Q->rear)
		return(FALSE);
	*x=Q->element[Q->front];
	return(TURE);
}
void YangHuiTriangle()
{
	int n,i,temp,x,N;
	SeqQueue Q;
	InitQueue(&Q,50);
	EnterQueue(&Q,1);
	printf("Please input N:");
	scanf("%d",&N);
	for(n=2;n<=N;n++)
	{
		EnterQueue(&Q,1);
		for(i=1;i<=n-2;i++)
		{
			DeleteQueue(&Q,&temp);
			printf("%8d",temp);
			GetHead(&Q,&x);
			temp=temp+x;
			EnterQueue(&Q,temp);
			
		}
		DeleteQueue(&Q,&x);
		printf("%8d",x);
		EnterQueue(&Q,1);
		printf("\n");
	}
	while(Q.front!=Q.rear)
	{
		DeleteQueue(&Q,&x);
		printf("%8d",x);
	}
		printf("\n");
	printf("Q`s address=%p\n",Q.element);
	free(Q.element);
	printf("Q`s address=%p\n",Q.element);
}

int main()
{
	YangHuiTriangle();
}



